package com.example.zhu95.mytimber.entity

import org.litepal.crud.DataSupport


/**
 * @author zhu95
 * @date 2017/12/27 22:59
 *
 * 播放列表对应的实体类
 *
 */
data class PlayListBean(

        /**
         * 播放列表名
         */
        var title: String = "",
        /**
         * 播放列表包含的歌曲id，使用 $ 分隔id
         */
        var songIds: String = "",
        /**
         * 是否是自动列表
         */
        var isDefaultList: Boolean = false
) : DataSupport() {

    fun getSongIDs(): List<String>? {
        if (songIds == "") {
            return null;
        }
        val split = songIds.split('$');
        return split
    }

    /**
     * 播放列表中第一首歌的专辑的图片
     */
    fun getAlbumArt(): String? {
        val songIDs = getSongIDs()
        if (songIDs != null && songIDs.isNotEmpty()) {
            val songID = songIDs.get(0).toInt()
            for (song in SongData.songs) {
                if (song.id == songID) {
                    return song.albumArt;
                }
            }
        }
        return null
    }

    override fun equals(other: Any?): Boolean {
        if (!(other is PlayListBean)) {
            return false
        }
        if (other.title == this.title && other.isDefaultList == this.isDefaultList && other.songIds == this.songIds) {
            return true
        }
        return false
    }

}